// --------------------------------------------------------------------------------------------------------------------
// <copyright file="DefaultWorkScheduler.cs" company="AzureContrib (Open source library http://azurecontrib.codeplex.com)">
//   Microsoft Public License (Ms-PL)
// </copyright>
// <summary>
//   The default <see cref="IWorkScheduler" /> that orders the <see cref="IWorkItem" /> according to <see cref="IWorkItemMetadata.Order" />
// </summary>
// --------------------------------------------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;

namespace AzureContrib.WindowsAzure.WorkServices
{
	/// <summary>
	/// The default <see cref="IWorkScheduler"/> that orders the <see cref="IWorkItem"/> according to <see cref="IWorkItemMetadata.Order"/>
	/// </summary>
	[WorkSchedulerMetadata(WorkSchedulerNames.DefaultWorkSchedulerName, WorkSchedulerNames.DefaultWorkSchedulerDescription)]
	internal class DefaultWorkScheduler : IWorkScheduler
	{
		/// <summary>
		/// Schedule work in a useful order. <see cref="IWorkScheduler.ScheduleWork"/>
		/// </summary>
		/// <param name="works">The work to schedule.</param>
		/// <returns>
		/// The work ordered by the scheduler.
		/// </returns>
		public IOrderedEnumerable<Lazy<IWork>> ScheduleWork(IEnumerable<Lazy<IWork>> works)
		{
			return works.OrderBy(w => w.Value.Order);
		}
	}
}